//
//  ZYCStuAttendanceRecordCell.m
//  ZDSC
//
//  Created by ZDTX on 2021/7/27.
//

#import "ZYCStuAttendanceRecordCell.h"
#import "ZYCAttendanceRecordModel.h"
@interface ZYCStuAttendanceRecordCell ()

@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *timeLabel;
@property (nonatomic, strong) UILabel *temperatureLabel;
@property (nonatomic, strong) UILabel *markLabel;
@property (nonatomic, strong) UILabel *line;
@end
@implementation ZYCStuAttendanceRecordCell

- (void)setModel:(ZYCAttendanceRecordModel *)model{
    _model = model;
    _nameLabel.attributedText = [self returnFuwenBen:[NSString stringWithFormat:@"%@/%@",model.studentName,model.attendanceStatusStr]];
    
    NSString *entryTimeString  = nil;
    if (model.entryTime.length > 0){
        entryTimeString = [NSString stringWithFormat:@"时间:%@",model.entryTime];
    } else{
        entryTimeString = @"时间:无";
    }
    _timeLabel.text = entryTimeString;
    NSString *temperatureString  = nil;
    if (model.temperature.length > 0){
        temperatureString = [NSString stringWithFormat:@"温度:%@",model.temperature];
    } else{
        temperatureString = @"温度:无";
    }
    _temperatureLabel.text = temperatureString;
    _markLabel.text = [NSString stringWithFormat:@"备注:%@",model.durationLeaveStr];
}

- (NSMutableAttributedString *)returnFuwenBen:(NSString *)string{
    NSMutableAttributedString *attriString = [[NSMutableAttributedString alloc] initWithString:string];
    NSRange rang0 = NSMakeRange(0, self.model.studentName.length);
    [attriString addAttribute:NSFontAttributeName value:kCustomFont(@"PingFangSC-Medium", 17.0f) range:rang0];
    NSRange rang1 = NSMakeRange(self.model.studentName.length, self.model.attendanceStatusStr.length + 1);
    if ([self.model.attendanceStatus integerValue]  == 1) {
        [attriString addAttribute:NSForegroundColorAttributeName value:HEX_RGB(@"#2B302D") range:rang1];
        [attriString addAttribute:NSFontAttributeName value:kCustomFont(@"PingFangSC-Medium", 14.0f) range:rang1];
    }else if([self.model.attendanceStatus integerValue]  == 2){
        [attriString addAttribute:NSForegroundColorAttributeName value:HEX_RGB(@"#39A85B") range:rang1];
        [attriString addAttribute:NSFontAttributeName value:kCustomFont(@"PingFangSC-Medium", 14.0f) range:rang1];
    }else if([self.model.attendanceStatus integerValue]  == 3){
        [attriString addAttribute:NSForegroundColorAttributeName value:HEX_RGB(@"#E93C06") range:rang1];
        [attriString addAttribute:NSFontAttributeName value:kCustomFont(@"PingFangSC-Medium", 14.0f) range:rang1];
    }else{
        [attriString addAttribute:NSForegroundColorAttributeName value:HEX_RGB(@"#FDA252") range:rang1];
        [attriString addAttribute:NSFontAttributeName value:kCustomFont(@"PingFangSC-Medium", 14.0f) range:rang1];

    }
    return attriString;;
    
}


- (void)setDic:(NSDictionary *)dic{
    _dic = dic;
    _nameLabel.text = dic[@"name"];
    _timeLabel.text = dic[@"time"];
    _temperatureLabel.text = dic[@"temperature"];
    _markLabel.text = dic[@"mark"];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.nameLabel];
        [self.contentView addSubview:self.timeLabel];
        [self.contentView addSubview:self.temperatureLabel];
        [self.contentView addSubview:self.line];
        [self.contentView addSubview:self.markLabel];
        
        [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(19.0f);
            make.top.equalTo(self.contentView).offset(20.0f);
        }];
        [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.contentView);
            make.centerY.equalTo(self.nameLabel);
        }];
        [self.temperatureLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView).offset(-30.0f);
            make.centerY.equalTo(self.nameLabel);
        }];
        [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(20.0f);
            make.right.equalTo(self.contentView).offset(-20.0f);
            make.top.equalTo(self.nameLabel.mas_bottom).offset(17.0f);
            make.height.mas_equalTo(1);
        }];
        
        [self.markLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(20.0f);
            make.bottom.equalTo(self.contentView).offset(-15.0f);
        }];
    }
    return self;
}

- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Regular", 17.0f) titleColor:HEX_RGB(@"#262A28") textAlignment:ZZTextAlignmentLeft];
    }
    return _nameLabel;
}
- (UILabel *)timeLabel {
    if (!_timeLabel) {
        _timeLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Light", 14.0f) titleColor:HEX_RGB(@"#888888") textAlignment:ZZTextAlignmentLeft];
    }
    return _timeLabel;
}

- (UILabel *)temperatureLabel {
    if (!_temperatureLabel) {
        _temperatureLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Light", 14.0f) titleColor:HEX_RGB(@"#888888") textAlignment:ZZTextAlignmentLeft];
    }
    return _temperatureLabel;
}

- (UILabel *)markLabel {
    if (!_markLabel) {
        _markLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Light", 14.0f) titleColor:HEX_RGB(@"#888888") textAlignment:ZZTextAlignmentLeft];
    }
    return _markLabel;
}

- (UILabel *)line {
    if (!_line) {
        _line = [[UILabel alloc] init];
        _line.backgroundColor = HEX_RGB(@"#EAEAEA");
    }
    return _line;
}

@end
